﻿// -----------------------------------------------------------------------
// <copyright file="SimpleContainer.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace mmonkey.core
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Ninject;
    using mmonkey.core.Services;
    using mmonkey.core.Modules;
    using Ninject.Modules;

    /// <summary>
    /// Singleton IoC Container
    /// </summary>
    public static class SimpleContainer
    {
        private static readonly IKernel _kernel = new StandardKernel(new NinjectSettings() { LoadExtensions = false });
        private static bool _init = false;

        public static void Initialize(bool designMode)
        {
            if (!_init)
            {
                _kernel.Load(new CoreNinjectModule());
                _init = true;
            }
        }

        public static bool Initialized
        {
            get { return _init; }
        }

        public static IKernel Kernel
        {
            get { return _kernel; }
        }

        public static T Resolve<T>(params Ninject.Parameters.IParameter[] parameters)
        {
            return _kernel.Get<T>(parameters);
        }

        public static T Resolve<T>(string name, params Ninject.Parameters.IParameter[] parameters)
        {
            return _kernel.Get<T>(name, parameters);
        }

        public static IEnumerable<T> ResolveAll<T>(params Ninject.Parameters.IParameter[] parameters)
        {
            return _kernel.GetAll<T>(parameters);
        }

        public static void Load(params INinjectModule[] modules)
        {
            _kernel.Load(modules);
        }
    }
}
